package com.homework.ch06;

public class InstanceCounter {
    // 静态变量：记录实例化次数（所有对象共享）
    private static int instanceCount = 0;

    // 构造方法：每次创建对象时计数器+1
    public InstanceCounter() {
        instanceCount++;
        System.out.println("创建第 " + instanceCount + " 个实例");
    }

    // 静态方法：获取当前实例化次数
    public static int getInstanceCount() {
        return instanceCount;
    }

    // 静态方法：重置计数器（可选功能）
    public static void resetCount() {
        instanceCount = 0;
        System.out.println("计数器已重置");
    }
}
